﻿using DotNetMVC.IDAL;
using DotNetMVC.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DotNetMVC.DAL
{
    public partial class PermissionDal : BaseDal<Permission>, IPermissionDal
    {
        /// <summary>
        /// 获取管理员权限菜单
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public IQueryable<Permission> GetPermMenusByUserId(long userId)
        {
            IQueryable<Permission> perms = from adminUser in ctx.Set<AdminUser>()
                                           join adminUserRole in ctx.Set<AdminUserRole>() on adminUser.Id equals adminUserRole.AdminUserId
                                           join role in ctx.Set<Role>() on adminUserRole.RoleId equals role.Id
                                           join rolePermission in ctx.Set<RolePermission>() on role.Id equals rolePermission.RoleId
                                           join permission in ctx.Set<Permission>() on rolePermission.PermissionId equals permission.Id
                                           where adminUser.Id == userId && permission.IsMenu == true
                                           select permission;

            return perms;
        }
    }
}
